using System;
using System.Collections.Generic;
namespace RpgServiceLib.StoryFlagVariable
{
	public class StoryFlagVariableFactory
	{
		protected Dictionary<string, IStoryFlagVariable> ListOfFlagVariable {get;set;}  
		protected bool ThrowExceptionIfWrongVal{get;set;}
		protected StoryFlagVariableChangeHandlerManager DefaultChangeHandler {get;set;}
		
		public StoryFlagVariableFactory (bool checkVal, StoryFlagVariableChangeHandlerManager defHandler)
		{
			this.ListOfFlagVariable = new Dictionary<string, IStoryFlagVariable>();
			this.ThrowExceptionIfWrongVal = checkVal;
			this.DefaultChangeHandler = defHandler;
		}
		
		public StoryFlagVariable<bool> CreateBoolFlag(string name, bool startVal)
		{
			StoryFlagVariable<bool> bFlag = new StoryFlagVariable<bool>(name, startVal, this.ThrowExceptionIfWrongVal);
			
			this.ListOfFlagVariable.Add(name, bFlag );
			bFlag.change += DefaultChangeHandler.ConsumeChangeEvent;
			return bFlag;
		}
		
		public StoryFlagVariable<Int32> CreateNormalIntVariable (string name, Int32 startVal)
		{
			StoryFlagVariable<Int32> bFlag = new StoryFlagVariable<Int32> (name, startVal, this.ThrowExceptionIfWrongVal);
			
			this.ListOfFlagVariable.Add (name, bFlag);
			bFlag.change += DefaultChangeHandler.ConsumeChangeEvent;
			
			return bFlag;
		}

		public StoryFlagVariable<Int64> CreateLongIntVariable (string name, Int64 startVal)
		{
			StoryFlagVariable<Int64> bFlag = new StoryFlagVariable<Int64> (name, startVal, this.ThrowExceptionIfWrongVal);
			
			this.ListOfFlagVariable.Add (name, bFlag);
			bFlag.change += DefaultChangeHandler.ConsumeChangeEvent;
			
			return bFlag;
		}

		public StoryFlagVariable<UInt32> CreateUnsignedNormalIntVariable (string name, UInt32 startVal)
		{
			StoryFlagVariable<UInt32> bFlag = new StoryFlagVariable<UInt32> (name, startVal, this.ThrowExceptionIfWrongVal);
			
			this.ListOfFlagVariable.Add (name, bFlag);
			bFlag.change += DefaultChangeHandler.ConsumeChangeEvent;
			
			return bFlag;
		}

		public StoryFlagVariable<UInt64> CreateUnsignedLongIntVariable (string name, UInt64 startVal)
		{
			StoryFlagVariable<UInt64> bFlag = new StoryFlagVariable<UInt64> (name, startVal, this.ThrowExceptionIfWrongVal);
			
			this.ListOfFlagVariable.Add (name, bFlag);
			bFlag.change += DefaultChangeHandler.ConsumeChangeEvent;
			
			return bFlag;
		}

		public StoryFlagVariable<string> CreateTextVariable (string name, string startVal)
		{
			StoryFlagVariable<string> bFlag = new StoryFlagVariable<string> (name, startVal, this.ThrowExceptionIfWrongVal);
			
			this.ListOfFlagVariable.Add (name, bFlag);
			bFlag.change += DefaultChangeHandler.ConsumeChangeEvent;
			
			return bFlag;
		}

		public StoryFlagVariable<double> CreateDoubleFloatVariable (string name, double startVal)
		{
			StoryFlagVariable<double> bFlag = new StoryFlagVariable<double> (name, startVal, this.ThrowExceptionIfWrongVal);
			
			this.ListOfFlagVariable.Add (name, bFlag);
			bFlag.change += DefaultChangeHandler.ConsumeChangeEvent;
			
			return bFlag;
		}


		public StoryFlagVariable<decimal> CreateDecimalVariable (string name, decimal startVal)
		{
			StoryFlagVariable<decimal> bFlag = new StoryFlagVariable<decimal> (name, startVal, this.ThrowExceptionIfWrongVal);
			
			this.ListOfFlagVariable.Add (name, bFlag);
			bFlag.change += DefaultChangeHandler.ConsumeChangeEvent;
			
			return bFlag;
		}

		public StoryFlagVariable<byte> CreateByteVariable (string name, byte startVal)
		{
			StoryFlagVariable<byte> bFlag = new StoryFlagVariable<byte> (name, startVal, this.ThrowExceptionIfWrongVal);
			
			this.ListOfFlagVariable.Add (name, bFlag);
			bFlag.change += DefaultChangeHandler.ConsumeChangeEvent;
			
			return bFlag;
		}
		
		public IStoryFlagVariable GetFlagOrVariableByName(string name)
		{
			return ListOfFlagVariable[name];
		}
	}
}

